<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">

<head th:fragment="head(title)">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title th:replace="${title}">前台段落</title>
    <link rel="icon" th:href="@{/layuimini/images/favicon.ico}">
    <link rel="stylesheet" th:href="@{/css/me.css}">
    <link rel="stylesheet" th:href="@{/lib/semantic/semantic.min.css}">
    <link rel="stylesheet" th:href="@{/css/typo.css}">
    <link rel="stylesheet" th:href="@{/css/animate.css}">
    <link rel="stylesheet" th:href="@{/lib/prism/css/prism.css}">
    <link rel="stylesheet" th:href="@{/lib/tocbot/tocbot.css}">
    <link rel="stylesheet" th:href="@{/layuimini/lib/layui-v2.6.3/css/layui.css}" media="all">
</head>

<body>

<!--导航-->
<nav th:fragment="nav(n)" class="gird-header">
    <div class="ui container">
        <div class="ui inverted secondary stackable menu">
            <a th:href="@{/}"><h2 class="ui olive header item">风铃</h2></a>
            <a th:href="@{/}" class="m-item item m-mobile-hide" th:classappend="${n == 1} ? 'active'"><i class="home icon"></i>首页</a>
            <a th:href="@{/types}" class="m-item item m-mobile-hide" th:classappend="${n == 2} ? 'active'"><i class="idea icon"></i>分类</a>
            <a th:href="@{/friends}" class="m-item item m-mobile-hide" th:classappend="${n == 3} ? 'active'"><i class="pencil alternate icon"></i>友链</a>
            <a th:href="@{/resources}" class="m-item item m-mobile-hide" th:classappend="${n == 4} ? 'active'"><i class="graduation cap icon"></i>资源库</a>
            <a th:href="@{/archives}" class="m-item item m-mobile-hide" th:classappend="${n == 5} ? 'active'"><i class="clone icon"></i>归档</a>
            <div class="m-item item right m-mobile-hide">
                <form th:action="@{/search}" name="search" target="_blank">
                    <div class="ui icon inverted transparent input m-margin-tb-tiny">
                        <input type="text" name="query" placeholder="Search....">
                        <i onclick="document.forms['search'].submit()" class="search link icon"></i>
                    </div>
                </form>
            </div>

            <!--TODO 此处显示不太好，后续可以继续优化-->
            <img id="userAvatar" style="display: none" class="right item image m-login-avatar m-mobile-hide" alt="">
            <div id="userLog" style="margin-left: -18px !important; display: none" class="ui dropdown item m-item m-mobile-hide">
                <div id="userName" class="text">张三</div>
                <i class="dropdown icon"></i>
                <div class="menu">
                    <div class="item">
                        <i class="cog icon"></i>
                        <a class="m-black">个人设置</a>
                    </div>
                    <div class="item">
                        <i class="retweet icon"></i>
                        <a th:href="@{/login}" class="m-black">切换登录</a>
                    </div>
                    <div class="item">
                        <i class="sign-out icon"></i>
                        <a onclick="logout()" class="m-black">退出登录</a>
                    </div>
                </div>
            </div>
            <a id="loginBtn" th:href="@{/login}" class="m-item right item m-mobile-hide"><i class="sign-in icon"></i>登录</a>
        </div>
    </div>
    <a href="#" class="ui menu toggle black icon button m-right-top m-mobile-show">
        <i class="sidebar icon"></i>
    </a>
</nav>

<!--底部栏-->
<footer th:fragment="footer" class="ui inverted vertical segment m-padded-tb-massive m-opacity">
    <!--容器-->
    <div class="ui center aligned container">
        <div class="ui inverted divided stackable grid">
            <div class="four wide column">
                <div class="ui inverted m-text-thin m-text-spaced m-margin-top-max m-footer-title">联系我</div>
                <div class="ui inverted link list">
                    <div class="m-text-thin">Email：<span th:text="#{email}">2540487435@qq.com</span></div>
                    <div class="m-text-thin">QQ：<span th:text="#{QQ}">2540487435</span></div>
                    <div class="m-text-thin">微信号：<span th:text="#{Wechat}">ldfwz0902</span></div>
                </div>
            </div>

            <div class="four wide column" >
                <div class="ui inverted link list">
                    <div class="item">
                        <!--微信二维码-->
                        <div class="ui inverted m-text-thin m-text-spaced m-footer-title">添加微信</div>
                        <img th:src="@{/images/wechat.png}" class="ui m-margin-top rounded image m-QR" alt="">
                    </div>
                </div>
            </div>

            <div class="four wide column">
                <div class="ui inverted link list">
                    <div class="item">
                        <!--qq群二维码-->
                        <div class="ui inverted m-text-thin m-text-spaced m-footer-title">添加QQ</div>
                        <img th:src="@{/images/QQ.jpeg}" class="ui m-margin-top rounded image m-QR" alt="">
                    </div>
                </div>
            </div>
            <!--博客运行时间统计-->
            <div class="four wide column">
                <div style="font-size: large;font-weight: bold" class="ui inverted m-text-thin m-text-spaced m-margin-top">博客总览</div>
                <div id="blog-message">
                    <div class="ui inverted link list m-padded-tiny m-margin-top" th:fragment="blogMessage">
                        <div class="m-text-thin m-footer-position">
                            文章总数： <h4 class="ui orange header m-inline-block m-margin-top-null" th:text="${blogNums}"> 1314 </h4> 篇
                        </div>
                        <div class="m-text-thin m-footer-position">
                            访问总数： <h4 class="ui orange header m-inline-block m-margin-top-null" th:text="${blogViews}"> 1314 </h4> 次
                        </div>
                        <div class="m-text-thin m-footer-position">
                            评论总数： <h4 class="ui orange header m-inline-block m-margin-top-null" th:text="${blogCommentNums}"> 1314 </h4> 条
                        </div>
                    </div>
                </div>
            </div>

        </div>
        <div class="ui inverted section divider"></div>
        <div class="ui inverted m-text-thin m-text-spaced m-footer-time">此网站已运行：<span id="timer" class="item m-text-thin"></span></div>
    </div>
</footer>

<th:block th:fragments="script">
    <script th:src="@{/layuimini/lib/jquery-3.4.1/jquery-3.4.1.min.js}"></script>
    <script th:src="@{/lib/semantic/semantic.min.js}"></script>
    <script th:src="@{/lib/waypoints/jquery.waypoints.min.js}"></script>
    <script src="//cdn.jsdelivr.net/npm/jquery.scrollto@2.1.2/jquery.scrollTo.min.js"></script>
    <script th:src="@{/lib/qrcode/qrcode.min.js}"></script>
    <script th:src="@{/lib/prism/js/prism.js}"></script>
    <script th:src="@{/lib/tocbot/tocbot.min.js}"></script>
    <script th:src="@{/layuimini/lib/layui-v2.6.3/layui.js}" charset="utf-8"></script>
    <script th:src="@{/layuimini/lib/jquery-3.4.1/jquery.cookie.js}"></script>
    <!--人物的看板娘-->
    <script src="https://eqcn.ajz.miesnfu.com/wp-content/plugins/wp-3d-pony/live2dw/lib/L2Dwidget.min.js"></script>

    <script>
        /*此处为网站的创建时间*/
        function setTime() {
            var create_time = Math.round(new Date(Date.UTC(2021, 6, 23, 0, 0, 0)).getTime() / 1000);
            var timestamp = Math.round((new Date().getTime() + 8 * 60 * 60 * 1000) / 1000);
            currentTime = secondToDate((timestamp - create_time));
            $('#timer').html(currentTime[0] + '年' + currentTime[1] + '天' + currentTime[2] + '时' + currentTime[3] + '分' + currentTime[4] + '秒')
        }
        setInterval(setTime, 1000)
        //计算时间
        function secondToDate(second) {
            if (!second) {
                return 0
            }
            var time = new Array(0, 0, 0, 0, 0)
            if (second >= 365 * 24 * 3600) {
                time[0] = parseInt(second / (365 * 24 * 3600))
                second %= 365 * 24 * 3600
            }
            if (second >= 24 * 3600) {
                time[1] = parseInt(second / (24 * 3600))
                second %= 24 * 3600
            }
            if (second >= 3600) {
                time[2] = parseInt(second / 3600)
                second %= 3600
            }
            if (second >= 60) {
                time[3] = parseInt(second / 60)
                second %= 60
            }
            if (second > 0) {
                time[4] = second
            }
            return time;
        }

        //看板娘初始化
        L2Dwidget.init({
            "model": {
                jsonPath: "https://unpkg.com/live2d-widget-model-miku@1.0.5/assets/miku.model.json",
                "scale": 1
            },
            "display": {
                "position": "left",
                "width": 120,
                "height": 170,
                "hOffset": 0,
                "vOffset": 0
            },
            "mobile": {
                "show": true,
                "scale": 0.5
            },
            "react": {
                "opacityDefault": 0.7,
                "opacityOnHover": 0.8
            },
        })

        //回到顶部按钮
        var waypoint = new Waypoint({
            element: $('#waypoint'),
            handler: function(direction) {
                if (direction == 'down') {
                    $('#toolbar').show(100)
                } else {
                    $('#toolbar').hide(500)
                }
            }
        })

        //手机汉堡菜单
        $('.menu.toggle').click(function () {
            $('.m-item').toggleClass('m-mobile-hide');
        })

        $('#blog-message').load(/*[[@{/footer/blogmessage}]]*/"/footer/blogmessage");

        //判断是是否登录
        $(function () {
            if ($.cookie('user') == undefined || $.cookie('user') == '' || $.cookie('user') == null) {
                $('#userAvatar').css("display","none")
                $('#userLog').css("display","none")
                $('#loginBtn').css("display","block")
            } else {
                var user = JSON.parse($.cookie('user'));
                var username = user.username;
                var avatar = user.avatar
                $('#userAvatar').css("display","block")
                $('#userLog').css("display","block")
                $('#loginBtn').css("display","none")
                $('#userName').html(username)
                $('#userAvatar').attr('src', avatar)
            }
        })

        // 设置下拉菜单而不变其文本值
        $('.ui.dropdown').dropdown({
            action: 'hide'
        })

        //注销
        function logout() {
            $.ajax({
                url: '/user/logout',
                type: 'post',
                success: function (res) {
                    $.cookie('user', '', { path: '/' })
                    layui.layer.msg(res.msg, function () {
                        window.location.reload()
                    })
                }
            })
        }

    </script>
</th:block>

</body>
</html>